package com.jason.lucene.example.search;

import org.apache.lucene.analysis.core.WhitespaceAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;

/**
 * @author he peng
 * @create 2017/12/6 19:22
 * @see
 */
public class BaseQueryTest {

    protected Directory dir;

    protected void indexingSingleFieldDocs(Field[] fields) throws Exception {
        this.dir = new RAMDirectory();
        IndexWriterConfig writerConf = new IndexWriterConfig(new WhitespaceAnalyzer());
        IndexWriter writer = new IndexWriter(this.dir, writerConf);
        for (Field field : fields) {
            Document doc = new Document();
            doc.add(field);
            writer.addDocument(doc);
            System.out.println("indexing doc =====> " + doc);
        }

        writer.close();
    }
}
